package kevin.hbase.analyse.stop;

import kevin.hbase.service.StopService;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

@Slf4j
public class StopHandler extends Thread {
    private int index;
    private final List<Map<String, Object>> list = new ArrayList<>();
    private CountDownLatch latch;
    private StopService stopService;

    public StopHandler(int index, StopService stopService, CountDownLatch latch) {
        this.index = index;
        this.latch = latch;
        this.stopService = stopService;
    }

    public boolean addMap(Map<String, Object> map) {
        list.add(map);
        return true;
    }

    @Override
    public void run() {
        try {
            long start1 = System.currentTimeMillis();
            stopService.stopAnalyse(list);
            long end1 = System.currentTimeMillis();
            log.info("StopHandler:{} cost(ms):{}", index, end1 - start1);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        } finally {
            latch.countDown();
        }
    }
}
